<?php

namespace app\common\model;

use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use think\Model;

/**
 * 短信验证码
 */
class Sms Extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    // 追加属性
    protected $append = [
    ];


  /**
   * 阿里云短信
   *
   */



  public static function createClient($accessKeyId, $accessKeySecret){

    $config = new \Darabonba\OpenApi\Models\Config([
      // 您的 AccessKey ID
      "accessKeyId" =>$accessKeyId,
      // 您的 AccessKey Secret
      "accessKeySecret" =>$accessKeySecret
    ]);
    // 访问的域名
    $config->endpoint = "dysmsapi.aliyuncs.com";
    return new Dysmsapi($config);
  }

  /**
   * @param string[] $args
   * @return void
   * 新订单通知
   */
  public static function main($technician_name,$mobile,$time){
    $client = self::createClient("LTAI5tLw3jsRJpTiZQ2NgYNW","wimjtXagmWILw37HcLDUN1aTdoPMWW");
    $sendSmsRequest = new SendSmsRequest([
      "signName" => "心到家科技",
      "templateCode" =>"SMS_256926545",
      "phoneNumbers" => $mobile,
      "templateParam" => "{\"name\":\"$technician_name\",\"time\":\"$time\"}"
    ]);

    $runtime = new RuntimeOptions([]);
    $resp = $client->sendSmsWithOptions($sendSmsRequest, $runtime);
    adlog('通知短信内容', json_encode($resp));
    return $resp;
  }


  /**
   * @param $technician_name
   * @param $mobile
   * @param $time
   * @return \AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsResponse
   * 技师解约
   */
  public static function termination_sms($technician_name,$mobile,$time){
    $client = self::createClient("LTAI5tLw3jsRJpTiZQ2NgYNW","wimjtXagmWILw37HcLDUN1aTdoPMWW");
    $sendSmsRequest = new SendSmsRequest([
      "signName" => "心到家科技",
      "templateCode" => "SMS_256971557",
      "phoneNumbers" => $mobile,
      "templateParam" => "{\"name\":\"$technician_name\",\"time\":\"$time\"}"
    ]);
    $runtime = new RuntimeOptions([]);
    $resp = $client->sendSmsWithOptions($sendSmsRequest, $runtime);
    adlog('通知短信内容', json_encode($resp));
    return $resp;
  }

  /**
   * @param $technician_name
   * @param $mobile
   * @param $time
   * @return \AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsResponse
   * 订单拒绝
   */
  public static function refund_sms($uname,$mobile,$time){
    $client = self::createClient("LTAI5tLw3jsRJpTiZQ2NgYNW","wimjtXagmWILw37HcLDUN1aTdoPMWW");
    $sendSmsRequest = new SendSmsRequest([
      "signName" => "心到家科技",
      "templateCode" => "SMS_256721811",
      "phoneNumbers" => $mobile,
      "templateParam" => "{\"name\":\"$uname\",\"time\":\"$time\"}"
    ]);
    $runtime = new RuntimeOptions([]);
    $resp = $client->sendSmsWithOptions($sendSmsRequest, $runtime);
    adlog('通知短信内容', json_encode($resp));
    return $resp;
  }


}
